package com.qo.qsdk.event;

public class Publisher implements IPublisher {

    private QSDKReceiver.Visitor<QSDKReceiver> mVisitor = new QSDKReceiver.Visitor<QSDKReceiver>() {

        @Override
        public void visit(QSDKReceiver receiver, int eventID, Object... args) {
            if (!receiver.hasScaned()) {
                receiver.scanSubscriber(receiver);
            }

            receiver.handle(eventID, args);
        }
    };

    private static class PublisherHolder {
        private static Publisher instance_ = new Publisher();

        private PublisherHolder() {
        }
    }

    public static Publisher instance() {
        return PublisherHolder.instance_;
    }

    @Override
    public void publish(int eventID, Object... args) {
        QSDKReceiver.visit(mVisitor, eventID, args);
    }
}
